package com.ysw.springbootproject.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author 月上微
 * @date 2025/1/6
 * @since 20:24
 */
public class SystemUtil {

    private SystemUtil() {

    }

    /**
     * 登录或注册成功后,生成保持用户登录状态会话 token 值
     *
     * @param src String
     * @return String
     */
    public static String genToken(String src) {
        if (null == src || "".equals(src)) {
            return null;
        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(src.getBytes());
            return new BigInteger(1, md.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
}
